package com.cow.index.module.baseinfo.user;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cow.framework.core.base.BaseComponent;
import com.cow.framework.core.exception.BusinessException;
import com.cow.index.comm.config.constant.MessageConstants;


/**
 * 数字字典管理
 *
 * @author yangsj 
 **/
@RestController
@EnableAutoConfiguration
@RequestMapping(value="/baseinfo/user")
public class UserController extends BaseComponent{
	/**根据姓名搜索用户*/
	@RequestMapping(value="/getUserByName")	
	public Object getUserByName(@RequestParam String name) throws Exception{
		return super.getAuthClient().loadUserByUsername(name);
	}
	
	/**查询部门下的人员*/
	@RequestMapping(value="/getUserByOrg")	
	public Object getUserByOrg(@RequestParam Long orgId) throws Exception{
		return super.getAuthClient().getOrgUser(orgId); 
	}

	/**密码修改*/
	@RequestMapping(value="/modifyPassword")	
	public Object modifyPassword(@RequestParam String oldPassword,@RequestParam String newPassword) throws Exception{
		String result = super.getAuthClient().modifyPassword(Long.valueOf(super.getCurUserId()), oldPassword, newPassword);
		if(result.equals("1")){
			result = "success";			
		}else if(result.equals("02")){
			throw new BusinessException("B1013",MessageConstants.B1013);
		}
		return result;
	}
}
